<template>
  <view class="bottomPanelGoods" style="border-radius: 20rpx;">
    <!-- <view class="total">共{{ cartInfo.length }}件商品</view> -->
    <view class="goodWrapper">
      <view class="item acea-row row-between-wrapper" v-for="cart in cartInfo" :key="cart.id">
        <view class="bottomPanelpictrue">
          <image :src="cart.productInfo.sliderImageArr[0]" class="image" />
        </view>
        <view class="bottomPaneltext">
			
			<view class="title-price">
				<view style="margin-bottom: 25px;">{{ cart.productInfo.storeName }}</view>
			</view>
			
			<!-- <view>数量 {{ cart.cartNum }}</view> -->
			<view style="display: flex;justify-content: space-between;align-items: center;">
				<view>
					价格：{{ cart.truePrice }}
				</view>
				<view class="cartNume">
					<uni-icons v-if="cartEdit==0" style="margin-left: 5rpx;" color="#4E8CEE" type="minus" size="23" @click="del(cart.id,cart.cartNum)"></uni-icons>
					<view style="margin-left: 15rpx;" class="input-price">
						{{cart.cartNum}}
					</view>
					 <uni-icons v-if="cartEdit==0" style="margin-left: 15rpx;" color="#4E8CEE" type="plus-filled" size="23" @click="add(cart.productInfo.id)"></uni-icons>
					
				</view>
			</view>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
	import { mapState, mapMutations, mapActions } from 'vuex';
	import { getCategory,postCartAdd, getProducts, postCartDel, changeCartNum, getCartCount} from '@/api/store';
export default {
  name: "OrderGoods",
  props: {
	  cartEdit: Number,
    evaluate: Number,
    cartInfo: {
      type: Array,
      default: () => []
    }
  },
  data: function() {
    return {
		btnClick:true
	};
  },
  computed: {
  	...mapState(['deviceInfo', 'deviceConect', 'deviceStauts']),
  },
  mounted: function() {},
  methods: {
    routerGo(cart) {
      this.$yrouter.push({
        path: "/pages/shop/GoodsEvaluate/index",
        query: { id: cart.unique }
      });
    },
	del(id,num){
		let that = this
		// if(!this.btnClick){
		// 	return;
		// }	
	this.btnClick = false
		changeCartNum(id,num - 1).then(function(res){
			if (!res.success) {
					uni.showToast({
						title: res.msg || res.data.msg || res.data.message,
						icon: 'none',
						duration: 2000
					});
					that.$emit("computePrice")
					setTimeout(()=>{
						that.btnClick = true
					},800)
					return;
				}
						
			 else {
				uni.showToast({
					title: '减少数量成功',
					icon: 'success',
					duration: 2000,
					complete: () => {
						that.$emit("computePrice")
						setTimeout(()=>{
							that.btnClick = true
						},800)
					}
				});
			}
		}).catch(error => {
						setTimeout(()=>{
							that.btnClick = true
						},1000)
					});
	},
	// 加入购物车；
	add: function(id) {
		let that = this
	
		let q = {
			productId: id,
			cartNum:1,
			deviceId:this.deviceInfo.deviceId
		};
	// if(!this.btnClick){
	// 		return;
	// 	}	
	this.btnClick = false
		postCartAdd(q)
			.then(function(res) {
			
				
					if (!res.data) {
						uni.showToast({
							title: res.msg || res.data.msg || res.data.message,
							icon: 'none',
							duration: 2000
						});
						setTimeout(()=>{
							that.btnClick = true
						},800)
						return;
					}
			
				 else {
					uni.showToast({
						title: '添加购物车成功',
						icon: 'success',
						duration: 2000,
						complete: () => {
							that.$emit("computePrice")
							setTimeout(()=>{
								that.btnClick = true
							},800)
						}
					});
				}
			})
			.catch(error => {
				setTimeout(()=>{
					that.btnClick = true
				},1000)
			});
	},
  }
};
</script>
